<template>
    <div class="ticket ticket-wrap" v-title="title">
        <div class="ticket-top">
            <!--<i class="iconfont icon-fanhui" @click="back()"></i>-->
            <z-history :type="2"></z-history>
            <span>电子票</span>
        </div>
        <div class="ticket-center">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <div class="swiper-slide" v-for="(str,index) in tickets">
                        <div class="slide-top">
                            <div class="slide-num">第{{index + 1}}张</div>
                            <div class="erweima" >
                                <canvas class="canvas" :id="'canvas' + index"></canvas>
                            </div>
                            <img class="signImg" v-if="str.status==5" src="../../assets/image/已退票.png" alt="">
                            <img class="signImg" v-if="str.status==3" src="../../assets/image/已过期.png" alt="">
                            <img class="signImg" v-if="str.status==4" src="../../assets/image/退票中.png" alt="">
                            <div class="slideNo">票号：{{str.ticketNo}}</div>
                        </div>
                        <div class="slide-bottom">
                            <div class="slide-name">名称：{{actDetail.activityTitle}}</div>
                            <div class="slide-text">时间：{{actDetail.actStartTime |stampFormate2}}</div>
                            <div class="slide-text">
                                <div style="float:left">地点：</div><p>{{address}}</p></div>
                            <div class="slide-text">状态：
                                <span class="font1" v-if="str.status == 1">待使用</span>
                                <span class="font1" v-if="str.status == 2">已使用</span>
                                <span class="font1" v-if="str.status == 3">已过期</span>
                                <span class="font1" v-if="str.status == 4">退票中</span>
                                <span class="font1" v-if="str.status == 5">已退票</span>
                            </div>
                            <div class="slide-text">票价：{{str.ticket.price / 100}}元</div>
                        </div>
                    </div>
                </div>
                <div class="swiper-pagination swiper-pagination-white" style="bottom:-0.5rem;"></div>
            </div>
            <div class="hint-T">
                <p>使用说明</p>
                <p>1、本商品凭票兑换，一次性使用，请勿复制或者转借他人</p>
                <p>2、请截图保存至手机或者打印携带，保持二维码清晰完整</p>
                <p>3、本商品由【{{publishUser}}】提供服务，其拥有最终解释权</p>
            </div>
            <!--<z-home></z-home>-->
        </div>
    </div>
</template>

<script>
    import {userService} from '../../service/userService'
    import 'swiper/dist/css/swiper.min.css';
    import QRCode from 'qrcode'
    // const swiper = (resolve) => {require(['swiper'],resolve)} //密码登录页面

    export default {
        data(){
            return{
                codes:'',
                bannerUrl:'',
                orderNo:'',
                actDetail:'',
                tickets:[],
                address:'',
                arrlength:'',publishUser:'',
            }
        },
        metaInfo () {
            // console.log(this);
            const title = '电子票'
            return {
                title,
                script: [{src: '/src/assets/js/swiper.min.js', type: 'text/javascript'}],
                meta: [
                    { vmid: 'description', name: 'description', content: '运联' },
                    { vmid: 'keyWords', name: 'keyWords', content: '运联' },
                ]
            }
        },
        mounted(){
            this.useqrcode();
        },
        methods:{
            useqrcode(){
                let that = this;
                let order1 = that.$route.params.orderNo;
                that.orderNo = order1;
                userService.getTicket(order1).then(function(res){
                    that.arrlength = res.data.datas.length;
//                    console.log(that.arrlength)
                    if(that.arrlength !== 0){
                        let tickets = res.data.datas;
                        that.tickets = tickets;
//                        console.log(tickets)
                        userService.getActivities({activityId: tickets[0].actId}).then(function (res) {
//                            console.log(res)
                            that.actDetail = res.data.datas;
                            that.publishUser = res.data.datas.publishUser;
                            that.address = that.actDetail.city + that.actDetail.prov + that.actDetail.dist + that.actDetail.activityAddress
//                            console.log('活动详情',that.actDetail)
                            if(Swiper){
                                that.updated();
                            }else{

                            }
                            for(let i = 0;i<that.arrlength;i++){
                                let canvasName = 'canvas'+ i;
                                let canvas = document.getElementById(canvasName+'');
//                                console.log(canvas)
                                QRCode.toCanvas(canvas, location.origin + '/d/' + that.tickets[i].ticketUrl, (error) => {
                                    if (error) {
//                                        console.log(error)
                                    } else {
//                                        console.log('success')
                                    }
                                })
                            }
                        })
                    }else{
                        alert('暂无电子票')
                    }
                });
            },
            updated() {
                let swiper = new Swiper('.swiper-container', {
                    centeredSlides: true,
                    pagination: '.swiper-pagination',
                    paginationClickable: true,
                    loop: false,
                    speed: 600,
                    spaceBetween: 10,
                    slidesPerView: 1.15,
                    onTouchEnd: function() {
                        swiper.startAutoplay()
                    }
                });
            },
            back:function(){
                let that = this;
                that.$router.go(-1)
            }
        },
    }
</script>

<style lang="less">
.ticket{
    width:100%;
    text-align: center;
    background-image: linear-gradient(-122deg, #6DD7F1 0%, #6699FF 100%);
    .ticket-top{
        width:100%;
        height:1.2rem;
        i{
            width:0.86rem;
            height:0.86rem;
            border-radius: 100%;
            background:#356A77;
            float:left;
            font-size:0.8rem;
            margin-left:0.2rem;
            margin-top:0.16rem;
            color:#fff;
            display: block;
        }
        span{
            height:1.2rem;
            line-height:1.2rem;
            font-size: 18px;
            color:#fff;
            letter-spacing: 0.3px;
        }
    }
    .ticket-center{
        width:100%;
        overflow: hidden;
        padding:0.53rem 0;
        box-sizing: border-box;
        .swiper-container{
            width:100%;
            height:14rem;
            overflow: visible;
            .swiper-wrapper{
                width:100%;
                height:100%;
                .swiper-slide-active{
                    width:92%;
                    height:100% !important;
                    margin-top: 0  !important;
                }
                .swiper-slide{
                    width:92%;
                    height:94%;
                    background:url("../../assets/image/ticketbk.png")no-repeat;
                    background-size:100% 100%;
                    margin-top: 0.5rem;
                    .slide-top{
                        width:100%;
                        height: 7.3rem;
                        padding-top:0.4rem;
                        box-sizing: border-box;
                        position:relative;
                        .slide-num{
                            width:100%;
                            height:0.8rem;
                            line-height:0.8rem;
                            font-size: 12px;
                            color: #666666;
                            letter-spacing: 0.2px;
                        }
                        .signImg{
                            position: absolute;
                            transform: rotate(15deg);
                            width: 2rem;
                            bottom: 3.3rem;
                            right: 3.3rem;
                            background: #fff;
                        }
                        .erweima{
                            width:4.37rem;
                            height:4.3rem;
                            margin:0.1rem auto;
                            canvas{
                                width:100% !important;
                                height:100% !important;
                            }
                        }
                        .slideNo{
                            width:100%;
                            height:0.8rem;
                            line-height:0.8rem;
                            font-size: 14px;
                            color: #333333;
                            letter-spacing: 0;
                        }
                    }
                    .slide-bottom{
                        text-align: left;
                        padding:0 0.73rem;
                        box-sizing: border-box;
                        .slide-name{
                            width:100%;
                            height:0.8rem;
                            line-height:0.8rem;
                            overflow: hidden;
                            text-overflow:ellipsis;
                            white-space: nowrap;
                            margin:0.25rem 0;
                            font-size: 14px;
                            color: #333333;
                            letter-spacing: 0;
                        }
                        .slide-text{
                            width:100%;
                            margin:0.25rem 0;
                            font-size: 14px;
                            color: #333333;
                            letter-spacing: 0;
                            overflow: hidden;
                            p:nth-child(1){
                                width: 1.3rem;
                                float:left;
                            }
                            p:nth-child(2){
                                width:5.86rem;
                                float:left;
                            }
                            span{
                                font-size: 14px;
                                letter-spacing: 0;
                                line-height: 20px;
                                color:#68B0F9;
                            }
                        }
                    }
                }
            }
        }
        .hint-T{
            width:100%;
            padding:0.6rem;
            box-sizing: border-box;
            text-align: left;
            font-size: 14px;
            color: #FFFFFF;
            letter-spacing: 0;
            p:nth-child(1){
                margin:0.5rem 0;
            }
        }
    }
}
</style>